package com.central.apps.controller;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.central.app.service.HandlerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "课题号树")
@RequestMapping("/obj")
public class PrController {
    @Autowired
    private HandlerService handlerService;

    @GetMapping("/findByCodeTree/{pcode}")
    @ApiOperation(value = "查询课题号树")
    public List<Map<String, Object>> findChildTree(@PathVariable String pcode){

        List<Map<String, Object>> datas = new ArrayList<>();
        String proparentid = "";
        if(pcode!=null){
            proparentid = pcode;
        }
        String sql = "select * from gq_proaccount where proparentid =' "+proparentid+"'";
        List<Map<String, Object>> list = handlerService.findBySql(sql);
        for (Map<String, Object> stringObjectMap : list) {
            //查询是否有无子集
            String sql1 = "select id from gq_proaccount where proparentid =' "+stringObjectMap.get("id")+"'";
            List<Map<String, Object>> list1 = handlerService.findBySql(sql1);
            boolean issubset = false;
            if (CollectionUtils.isNotEmpty(list1)) {
                issubset=true;
            }
            stringObjectMap.put("issubset",issubset);
            datas.add(stringObjectMap);
        }

        return datas;
    }

    @GetMapping("/findByCodeTree1/{pcode}")
    @ApiOperation(value = "查询课题号树")
    public List<Map<String, Object>> findChildTree1(@PathVariable String pcode){

        List<Map<String, Object>> datas = new ArrayList<>();
        String proparentid = "";
        if(pcode!=null){
            proparentid = pcode;
        }
        String sql = "select * from gq_proaccount where proparentid =' "+proparentid+"'";

        return handlerService.findBySql(sql);
    }
}
